﻿using System;
using System.Collections.Generic;
using System.Text;

using Torch.WL.DataAccess.CleanChina;
using Torch.WL.Entity.CleanChina;
using Torch.FrameWork.Utility;

namespace Torch.WL.Business.CleanChina
{
    class TbForumManager
    {
        private readonly TbForumAccess dal = new TbForumAccess();

        private static TbForumManager _personManager;
        public static TbForumManager Instance()
        {
            if (null == _personManager )
                _personManager = new TbForumManager();

            return _personManager;
        }

        private TbForumManager()
        {         
        }

        public List<TbForumEntity> QueryForum(int onlygettodayforum, string querykey,
            int timesort,
            int timesorttype,
            int classsort,
            int classsorttype
            )
        {
            return dal.QueryForum(onlygettodayforum,querykey,timesort,timesorttype,classsort,classsorttype);
            
        }

        public TbForumEntity GetModelByCache(int forumId)
        {

            string CacheKey = "TbForumEntityModel-" + forumId;
            object objModel = DataCache.GetCache(CacheKey);
            if (objModel == null)
            {
                try
                {
                    objModel = dal.GetModel(forumId);
                    if (objModel != null)
                    {
                        int ModelCache = ConfigHelper.GetConfigInt("EntityCacheMinutes");
                        DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
                    }
                }
                catch { }
            }
            return (TbForumEntity)objModel;
        }




    }
}
